{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
.file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
.file-item .info{overflow: hidden;}
.uploader-list{width: 100%; overflow: hidden;}
</style>
<style>
	.layui-upload-list{display: flex;flex-wrap:wrap;}
	.layui-upload-list div{display: inline-block;text-align: center;cursor: pointer;flex-direction: column;display: flex;margin-right: 8px;}
	.layui-upload-list div img{height:100px;}
	.layui-upload-list div video{height:100px;}
	.layui-upload-list div span{display: block;}
	
	#div-slide_show_pic{display:flex;flex-wrap:wrap;}
	.item-img {
		flex-direction: column;
		display: flex;
		margin-right: 18px;
		margin-bottom:17px;width:12%;text-align:center;
	}
	.item-img img{max-width: 100%;}
	.delMultipleImgs4{text-align:center;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加/编辑</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" name="edit" id="edit" method="post" action="edit_article">
                    <input type="hidden" name="id" value="{$info.id??''}">
                    <input type="hidden" name="unit_id" value="{$unit_id??''}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">标题：</label>
                            <div class="input-group col-sm-4">
                                <input id="title" type="text" class="form-control" name="title" value="{$info.title??''}">
                            </div>
                        </div>
						
						
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">&nbsp;</span>课时文件</label>
							<div class="input-group col-sm-4">
								<span>{notempty name="$info['file_url']"}<video style="margin-left: 10px;height:80px;" src="{:isset($info.file_url)?$info.file_url:''}">{/notempty}</span>
								<input type="text" class="file_value form-control" value="{:isset($info.file_url)?$info.file_url:''}" name="file_url" lay-verify="uploadimg">
								<button type="button" class="layui-btn layui-btn-primary upload_img upload_img1" lay-data="{id:1}"><i class="layui-icon">&#xe67c;</i> 上传</button>   
							</div>
						</div>
                        
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit" id="c_s"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
  {include file="public/footer" /}

<script type="text/javascript" src="/static/admin/js/layui.js"></script>
<link rel="stylesheet" href="/static/admin/css/layui.css" media="all"/>
<script type="text/javascript">
layui.use(['upload'], function () {
	var upload = layui.upload;
	//单图上传
	upload.render({
		elem: '.upload_img',
		url: "{:url('Upload/upload_oss_video')}",
		accept:'video',
		acceptMime:'video/*',
		done: function(data){
			var id = this.id;
			var icon=5;
			if(!data.code){
				icon=6;
				//this.elem.prev().prev("span").html('<img style="margin-left: 10px;height:80px;" src="'+data.data.src+'">');
				//this.elem.prev(".file_value").val(data.data.src);
				$(".upload_img"+id).prev().prev("span").html('<video style="margin-left: 10px;height:100px;" src="'+data.data.src+'">');
				$(".upload_img"+id).prev(".file_value").val(data.data.src);
			}
			layer.msg(data.msg, {icon:icon,time: 1500});
		},
		error: function(){
			layer.msg('上传失败', {icon:icon,time: 1500});
		}
	});
});
</script>

<script type="text/javascript">
    $(function(){
        $('#edit').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm(){
            if( '' == $.trim($('#title').val())){
                layer.msg('标题不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
            if( '' == $.trim($('input[name="file_url"]').val())){
                layer.msg('课时文件不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
            

     }

        function complete(data){
            if(data.code == 1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                    window.location.href="{:url('course_less/index')}?unit_id={$unit_id}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
        }

    });


    //IOS开关样式配置
   var elem = document.querySelector('.js-switch');
        var switchery = new Switchery(elem, {
            color: '#1AB394'
        });
    var config = {
        '.chosen-select': {},                    
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }



</script>
</body>
</html>
